from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response

class page(PageNumberPagination):

    page_size = 6  # 后端指定每页显示数量
    page_size_query_param = 'pagesize'
    max_page_size = 10

    # 重写分页返回方法，按照指定的字段进行分页数据返回
    def get_paginated_response(self, data):
        data1 = []
        for i in data:
            dict1 = i
            dict2 = dict1['object']
            text = dict1['text']
            dict2['text']=text
            data1.append(dict2)



        return Response({
            'count': self.page.paginator.count, # 总数量
            'results': data1,  # 用户数据
            'next': self.get_next_link(),
            'previous': self.get_previous_link()
        })